<template>
  <div>
    <nav-header
      :headerTitle="headerTitle"
      :navBgColor="'#fff'"
      :headerNext="showHeaderTitle"
      @tap2next="tap2editArticle"
    ></nav-header>
    <div class="nav-height"></div>
    <div class="article-detail">
      <!-- 1版本 去除店铺及广告主相关信息 -->
      <!-- <div class="article-detail-header">
        <div class="artdetail-header-img">
          <img :src="userInfo.avatarUrl" alt />
        </div>
        <div class="artdetail-header-info">
          <p class="name">{{userInfo.nickName}}</p>
          <p class="aside">{{userInfo.brandName}}</p>
        </div>
        <div class="artdetail-header-phone">
          <div class @click="myDaili">联系TA</div>
        </div>
      </div> -->
      <div class="articleDetail">
        <!-- 1版本 去除店铺及广告主相关信息 -->
        <!-- <p class="title">{{articleInfo.articleTitle}}</p> -->
        <div class="content adw-content" v-html="articleInfo.articleContent"></div>
        <div class="null100" v-if="switchShowShopIndex==0 && isSelf"></div>
      </div>
      <!-- 1版本 去除店铺及广告主相关信息 -->
      <!-- <div class="show-shop" v-if="switchShowShopIndex==1">
        <div class="show-shop-insertbox"  v-if="isSelf">
          <p class>将我的店铺插入文章底部</p>
          <img class="switch-icon" :src="switchIcon" alt @click="switchShowShopInfo" />
        </div>
        <section class="shop-page" v-if="shopInfos">
          <my-shop-items
            :MyShopItems.sync="shopInfos"
            :ProductItems.sync="productItems" 
            :isProduct.sync="isShowProductList"
            :isSelf.sync="isSelf"
          ></my-shop-items>
        </section>
        <div class="agent-btn-box" v-if="!isSelf">
          <van-button class="agent-btn" type="default" @click="myDaili">我要代理</van-button>
        </div>
      </div> -->
      <!-- 1版本 去除店铺及广告主相关信息 -->
      <!-- <div class="article-detail-insertbox" v-if="switchShowShopIndex==0 && isSelf">
        <p class>将我的店铺插入文章底部</p>
        <img class="switch-icon" :src="switchIcon" alt @click="switchShowShopInfo" />
      </div> -->
      <div class="article-detail-footer" v-if="isSelf">
        <van-button :disabled="isDisabled" class="form-btn" type="default" @click="tap2nextOption">下一步</van-button>
      </div>
    </div>
    <!-- 1版本 去除店铺及广告主相关信息 -->
    <!-- <modal-dli
      :isModal.sync="modalDli.isModal"
      :wxName.sync="modalDli.wxName"
      :QQName.sync="modalDli.QQName"
      :phone.sync="modalDli.phone"
    ></modal-dli> -->
  </div>
</template>
<script>
import Vue from "vue";
import { Button, Toast ,Dialog } from "vant";
import navHeader from "@/components/NavHeader";
// 1版本 去除店铺及广告主相关信息 
// import MyShopItems from "@/components/MyShopItems";
// import ModalDli from "@/components/ModalDli";
import mixin from "@/utils/mixin";
import resetElement from "@/utils/aboutArticle/resetElement";
import audioSetup from "@/utils/aboutArticle/audio";
import setVideoSrc from "@/utils/aboutArticle/setVideoSrc";
// 1版本 去除店铺及广告主相关信息 
// import recommendOff from "@/assets/images/recommend_off.png";
// import recommendOn from "@/assets/images/recommend_on.png";
Vue.use(Button).use(Toast).use(Dialog);
export default {
  name: "articleDetail",
  mixins: [mixin],
  components: {
    navHeader,
    // 1版本 去除店铺及广告主相关信息 
    // MyShopItems,
    // ModalDli
  },
  computed: {
    showHeaderTitle() {
      return this.isSelf ? "编辑" : "";
    }
  },
  data() {
    return {
      headerTitle: "",
      articleInfo: {},
      isSelf: false,

      articleId:"",
      articleTitle:"",
      articleThumbnailsUrl:"",
      articleOverview:"",
      
      // 1版本 去除店铺及广告主相关信息 
      // shopInfos: {},
      // productItems: [],
      // isShowProductList:true,
      // userInfo: {},
      // switchShowShopIndex: 0,
      // switchIcon: recommendOff,  
      // modalDli: {
      //   isModal: false,
      //   wxName: "",
      //   QQName: "",
      //   phone: ""
      // }
      isDisabled: false,
    };
  },
  mounted() {
    let articleInfo =this.$route.query;  
    this.headerTitle = articleInfo.articleTitle;
    this.gainArticleDetail();
  },
  methods: {
    // 下一步 编辑
    tap2editArticle() {
      let query = this.$route.query;
      window.location.href = `./pages/editArticle.html?articleId=${query.articleId}&shareUniqueId=${query.shareUniqueId}`;
    },
    // 获取文章详情 初始化 (文章详情、店铺详情)
    gainArticleDetail() { 
      let { articleId, shareUniqueId } = this.$route.query;
      this.$http
        .post("article/getArticleDetailInfo", {
          articleId,
          uniqueId: window.localStorage.uniqueId,
          shareUniqueId
        })
        .then(
          res => {
            let resData = res.data.articleDetailInfo;
            this.articleInfo = resData.articleInfo;
            this.headerTitle = resData.articleInfo.articleTitle;
            
            this.articleTitle= resData.articleInfo.articleTitle;
            this.articleThumbnailsUrl= resData.articleInfo.articleThumbnailsUrl;
            this.articleOverview = resData.articleInfo.articleOverview ;
            this.articleId = resData.articleInfo.id; 
            // 1版本 去除店铺及广告主相关信息 
            // this.userInfo = resData.userInfo;
            // this.modalDli.wxName = resData.shopInfo.shopOwnerWxQrcodeUrl;
            // this.modalDli.QQName = resData.shopInfo.shopOwnerQqNum;
            // this.modalDli.phone = resData.shopInfo.shopOwnerTelNum;
            // window.localStorage.setItem(
            //   "ModalDli",
            //   JSON.stringify(this.modalDli)
            // );
            // // 判断是否有店铺
            // if(resData.shopInfo && resData.shopInfo.id){
            //   this.shopInfos = resData.shopInfo;
            //   this.shopInfos.shopId = resData.shopInfo.id;
            //   resData.productInfo.forEach((element,index) => {
            //     if(index < 3){
            //       this.productItems.push(element);
            //     }
            //   }); 
            //   console.log( this.productItems)
            //   if(this.productItems.length > 0){
            //     this.isShowProductList = true ; 
            //   }else{
            //     this.isShowProductList = false ;
            //   }
            // }else{
            //   this.shopInfos = null;
            // }
            
            // 判断为广告主自身还是其他
            if (resData.curUniqueId != resData.userInfo.uniqueId) {
              this.isSelf = false;
            } else {
              this.isSelf = true;
            } 
            // 1版本 去除店铺及广告主相关信息 
            // if(resData.shopLocationStatus == 0){
            //   this.switchIcon =   recommendOff;
            //   this.switchShowShopIndex =  0;
            // }else{
            //   this.switchIcon = recommendOn  ;
            //   this.switchShowShopIndex = 1;
            // }
            setTimeout(() => {
              // setVideoSrc.install();
              audioSetup.install();
              resetElement.install();
            }, 800);
          },
          err => {
            console.log(err) ;
          }
        );
    }, 
    // 1版本 去除店铺及广告主相关信息 
    // switchShowShopInfo() {
    //   if(!this.shopInfos){ 
    //     Dialog.confirm({
    //       message: "你还未创建店铺<br/>现在去添加！",
    //       showCancelButton: true,
    //       confirmButtonText: "去添加",
    //       beforeClose:(action,done)=>{
    //         done();
    //         if(action === "confirm"){
    //           this.$router.push("/adMine/editShop");
    //         }
    //       }
    //     });
    //     return false;
    //   }
    //   this.switchIcon = this.switchShowShopIndex == 0 ? recommendOn : recommendOff;
    //   this.switchShowShopIndex = this.switchShowShopIndex == 0 ? 1 : 0;
    // },
    // // 我要代理
    // myDaili() {
    //   this.modalDli.isModal = true;
    // },
    // 下一步 
    tap2nextOption(){
      // let sendData ={
      //   uniqueId:window.localStorage.uniqueId,
      //   shopLocationStatus:this.switchShowShopIndex
      // }
      // this.$http.post("user/sys/setting",sendData).then(
      //   () =>{
      //     Toast.success("文章设置成功");
      //     console.log("通知下一步") ;
      //   },
      //   err=>{
      //     console.log(err)
      //   }
      // )
      // 文章设置完成跳转下一步广告其他设置
      console.log(this.articleId,this.articleTitle,this.articleThumbnailsUrl);
      Toast({
        type:"success",
        message:"文章设置成功",
        onClose:()=>{
          let parmas = {
            articleId:this.articleId,
            articleTitle:this.articleTitle,
            articleThumbnailsUrl:this.articleThumbnailsUrl,  
            articleOverview:this.articleOverview
          };
          this.$bridge.callHandler('article2Ad',parmas,(res)=>{
            console.log(res)
          }) ;
        }
      });
    }
  }
};
</script>
<style lang="scss">
.article-detail {
  .articleDetail {
    .content {
      *:not(rect) {
        vertical-align: baseline;
        max-width: 100% !important;
        padding: 0;
        margin: 0;
        list-style: none;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        word-wrap: break-word;
        word-break: break-all;
        white-space: normal;
      }
      h1{
        line-height: 64px;
      }
      h2{
        line-height: 60px;
      }
      h3{
        line-height: 56px;
      }
      h4{
        line-height: 52px;
      }
      h5{
        line-height: 48px;
      }
      img {
        max-width: 100% !important;
        margin: 10px auto;
        background:url("~@/assets/images/image_default.png") no-repeat  center;
        background-size: cover; 
      }
      iframe {
        width: 100% !important;
        margin: 20px auto;
        &::-webkit-scrollbar {
          display: none;
          width: 0;
          height: 0;
          background-color: #fff;
        }
      }
      table {
        margin-bottom: 10px;
        border-collapse: collapse;
        display: table;
        width: 100% !important;
      }
      th {
        word-wrap: break-word;
        word-break: break-all;
        padding: 5px 10px;
        border: 1px solid #ddd;
      }
      td {
        word-wrap: break-word;
        word-break: break-all;
        padding: 5px 10px;
        border: 1px solid #ddd;
      }
    }
  }
}
/*  语音  */
.audio-section,
.audio-sectionmp {
  background: #fdfdfd;
  border: 1px solid #f1f1f1;
  position: relative;
  height: 140px;
  border-radius: 12px;
}

.audio-button {
  display: inline-block;
  position: absolute;
  left: 32px;
  top: 32px;
}

.audio-button:active {
  opacity: 0.5;
}

.audio-button.playing .play {
  display: none;
}

.audio-button .play {
  display: inline-block;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}

.audio-button .play .icon-pcduanbizhixiazaicishutubiao {
  font-size: 68px;
  color: #f56133;
}

.audio-button.playing .pause {
  display: inline-block;
}

.audio-button .pause {
  display: none;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}

.audio-button .pause .icon-yinlezanting {
  font-size: 80px;
  color: #f56133;
}
.audio-name {
  display: inline-block;
  font-size: 30px;
  font-weight: bold;
  position: absolute;
  left: 144px;
  top: 32px;
  right: 32px;
  overflow-y: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  height: 40px;
  line-height: 38px;
  text-align: left;
}

.audio-duration {
  display: inline-block;
  color: #a9a9a9;
  font-size: 26px;
  position: absolute;
  left: 144px;
  top: 76px;
}
</style>

<style scoped lang="scss">
@import "~@/assets/iconfont/iconfont.css";
.article-detail {
  margin: 0 auto 120px;
  .article-detail-header {
    width: 100%;
    height: 176px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    .artdetail-header-img {
      flex-basis: 184px;
      img {
        width: 126px;
        height: 126px;
        margin-left: 32px;
        border-radius: 50%;
      }
    }
    .artdetail-header-info {
      flex-basis: 342px;
      height: 100%;
      position: relative;
      text-align: left;
      .name {
        width: 100%;
        font-size: 40px;
        font-family: PingFangSC-Medium;
        font-weight: 700;
        color: rgba(48, 49, 51, 1);
        position: absolute;
        top: 40px;
        left: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .aside {
        width: 100%;
        font-size: 30px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        color: rgba(129, 129, 129, 1);
        position: absolute;
        bottom: 34px;
        left: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .artdetail-header-phone {
      flex-basis: 244px;
      height: 100%;
      position: relative;
      & > div {
        width: 188px;
        height: 64px;
        background: rgba(255, 37, 37, 1);
        border-radius: 8px;
        font-size: 32px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
        line-height: 64px;
        text-align: center;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 24px;
        margin: auto;
      }
    }
  }
  .articleDetail {
    width: 686px;
    margin: auto;
    .title {
      font-size: 40px;
      font-family: PingFangSC-Medium;
      font-weight: 700;
      color: rgba(48, 49, 51, 1);
      line-height: 56px;
      text-align: center;
      margin: 40px auto 0;
    }
    .content {
      font-size: 32px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(48, 49, 51, 1);
      line-height: 48px;
      margin-top: 32px;
    }
  }
  .show-shop {
    width: 100%;
    margin-top: 48px;
    position: relative;
    .show-shop-insertbox {
      width: 100%;
      height: 100px;
      background: rgba(0, 0, 0, 0.48);
      position: absolute;
      top: 0;
      left: 0;
      z-index: 9;
      font-size: 34px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: #fff;
      line-height: 100px;
      p {
        display: inline-block;
        width: 450px;
        height: 100%;
        margin-left: 32px;
        letter-spacing: 2px;
      }
      .switch-icon {
        width: 68px;
        position: absolute;
        top: 0;
        bottom: 0;
        right: 32px;
        margin: auto;
      }
    }
    .agent-btn-box {
      width: 750px;
      height: 142px;
      position: relative;
      .agent-btn {
        width: 300px;
        height: 88px;
        background: rgba(255, 37, 37, 1);
        border-radius: 44px;
        font-size: 34px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
        line-height: 88px;
        position: absolute;
        top: 0;
        bottom: 0;
        right: 32px;
        margin: auto;
      }
    }
  }
  .article-detail-insertbox {
    width: 100%;
    height: 100px;
    background: rgba(255, 231, 231, 1);
    position: fixed;
    bottom: 120px;
    left: 0;
    z-index: 9;
    font-size: 34px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    color: rgba(255, 37, 37, 1);
    line-height: 100px;
    p {
      display: inline-block;
      width: 450px;
      height: 100%;
      margin-left: 32px;
    }
    .switch-icon {
      width: 68px;
      position: absolute;
      top: 0;
      bottom: 0;
      right: 32px;
      margin: auto;
    }
  }
  .article-detail-footer {
    width: 100%;
    height: 120px;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 9;
    background: #fff;
    .form-btn {
      width: 562px;
      height: 88px;
      background: rgba(255, 37, 37, 1);
      border-radius: 44px;
      font-size: 34px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
      line-height: 88px;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
    }
  }
  .null100 {
    width: 100%;
    height: 100px;
  }
}
</style> 

